package com.xinzhi.controller;

import com.xinzhi.model.po.TAudit;
import com.xinzhi.model.vo.Aud;
import com.xinzhi.service.IAuditZz;
import com.xinzhi.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@RestController
@CrossOrigin
@Api(tags ="审核")
public class ZzAuditController {

    @Resource
    private IAuditZz iZzSpecial;

    @ApiOperation("审核主页内容")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "year", value = "年份", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pointid", value = "判加扣分", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "grade", value = "判成绩特殊", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "releaseState", value = "发布状态", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pagesize", value = "每页显示数", required = true, dataType = "int", paramType = "query")
    })
    @RequestMapping(value = "/specialAuditMain", method = RequestMethod.GET)
    public Result sMain1(Aud aud){
        System.out.println(aud);
        return iZzSpecial.getAll(aud.getYear(),aud.getReleaseState(),aud.getPointid(),aud.getGrade(), aud.getPage(),aud.getPagesize());
    }
    @ApiOperation("预审核内容")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "string", paramType = "query")
    })
    @RequestMapping(value = "/specialAudit", method = RequestMethod.GET)
    public Result sAudit(TAudit s){
        System.out.println(s);
        System.out.println(s.getId());
        return iZzSpecial.getPreAudit(s.getId());
    }


    @ApiOperation("预审核修改操作")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "auditopinion", value = "审核意见", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "auditnum", value = "审核分数", required = true, dataType = "string", paramType = "query")
    })
    @RequestMapping(value = "/specialUpdate", method = RequestMethod.GET)
    public Result sUpdateAudit(TAudit s){
        System.out.println(s.getAuditopinion());
        System.out.println(s.getAuditnum());
        System.out.println(s.getAuditstate());
        return iZzSpecial.updatePreAudit(s.getId(),s.getAuditopinion(),s.getAuditnum());
    }
    @ApiOperation("审核发布撤回")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "ReleaseState", value = "发布状态", required = true, dataType = "string", paramType = "query")
    })
    @RequestMapping(value = "/specialUpdateRelease", method = RequestMethod.GET)
    public Result sUpdateRelease(TAudit s){
        System.out.println(s.getId());
        return iZzSpecial.updateReleaseState(s.getId(),s.getReleaseState());
    }

    @ApiOperation("根据传入文件获取预审核数据")
    @ResponseBody
    @RequestMapping(value = "/upload", method = RequestMethod.GET)
    public Result handleFileUpload(MultipartFile file) {
        String path1=null;

        String filePath = "C:/Users/Administrator/Desktop/";

        if (!file.isEmpty()) {
            try {
                byte[] bytes = file.getBytes();
                Path path = Paths.get(filePath + file.getOriginalFilename());
                Files.write(path, bytes);
                path1=path.toString();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return iZzSpecial.getUpdateDate(path1);
    }

}
